import static org.junit.Assert.*;

import org.junit.Test;

//@author A0105195J

public class TestTimeParser {

	// The main purpose of the TimeParser unit is to support multiple date and
	// time formats
	// so the test cases have been partitioned into the formats supported by the
	// TimeParser.

	// There are minor changes to be made to the TimeParser before running the
	// tests. Please read the comments in TimeParser.java before proceeding

	// The 3 broad partitions are:
	// 1.Date including Time,
	// 2.Date without the time and
	// 3.Special cases that test for the trimming of the text field and wrapping
	// of the dates

	@Test
	public void test() {

		// Partition 1
		// Date including Time
		// Sub category 1a: Time consists of hour only
		assertEquals("dd MMMMM hhaaa", "Jan 01 2014 12:00",
				TimeParser.parseTime("1 jan 12pm"));

		assertEquals("dd MMMMM yy hhaaa", "Jan 01 2013 12:00",
				TimeParser.parseTime("1 jan 2013 12pm"));

		assertEquals("MMMMM dd hhaaa", "Feb 01 2014 12:00",
				TimeParser.parseTime("feb 1 12pm"));

		assertEquals("MMMMM dd yy hhaaa", "Oct 01 2013 12:00",
				TimeParser.parseTime("oct 1 2013 12pm"));

		assertEquals("dd/MM hhaaa", "Jan 01 2014 12:00",
				TimeParser.parseTime("1/1 12pm"));

		assertEquals("dd/MM/yyyy hhaaa", "Jan 01 2013 12:00",
				TimeParser.parseTime("1/1/2013 12pm"));

		// Giving the full month

		assertEquals("MMMMM dd yy hhaaa", "Oct 01 2013 12:00",
				TimeParser.parseTime("october  1 2013 12pm"));

		// Sub category 1b: Time consists of hour and minute

		assertEquals("dd MMMMM h.mmaaa", "Jan 01 2014 12:20",
				TimeParser.parseTime("1 jan 12.20pm"));

		assertEquals("dd MMMMM yy hh.mmaaa", "Jan 01 2013 12:20",
				TimeParser.parseTime("1 jan 2013 12.20pm"));

		assertEquals("MMMMM dd yy h.mmaaa", "Jan 01 2014 12:20",
				TimeParser.parseTime("jan 1 12.20pm"));

		assertEquals("MMMMM dd h.mmaaa", "Jan 01 2013 06:30",
				TimeParser.parseTime("jan 1 2013 6.30am"));

		assertEquals("dd/MM h.mmaaa", "Jan 01 2014 06:30",
				TimeParser.parseTime("1/1 6.30am"));

		assertEquals("dd/MM/yyyy h.mmaaa", "Jan 01 2013 06:30",
				TimeParser.parseTime("1/1/2013 6.30am"));

		// Partition 2
		// Date without Time

		assertEquals("dd MMMMM hhaaa", "Jan 01 2014 00:00",
				TimeParser.parseTime("1 jan"));

		assertEquals("dd MMMMM yy hhaaa", "Jan 01 2013 00:00",
				TimeParser.parseTime("1 jan 2013"));

		assertEquals("MMMMM dd hhaaa", "Jan 01 2014 00:00",
				TimeParser.parseTime("jan 1"));

		assertEquals("MMMMM dd yy hhaaa", "Jan 01 2013 00:00",
				TimeParser.parseTime("jan 1 2013"));

		assertEquals("dd/MM hhaaa", "Jan 01 2014 00:00",
				TimeParser.parseTime("1/1"));

		assertEquals("dd/MM/yyyy hhaaa", "Jan 01 2013 00:00",
				TimeParser.parseTime("1/1/2013"));

		// Partition 3
		// Sub Partition 3a: Special cases that test for the trimming of the
		// text field

		assertEquals("dd MMMMM h.mmaaa", "Jan 01 2014 12:20",
				TimeParser.parseTime("1st jan 12.20pm"));

		assertEquals("dd MMMMM yy hh.mmaaa", "Jan 25 2013 12:20",
				TimeParser.parseTime("25th jan 2013 12.20pm"));

		assertEquals("MMMMM dd yy h.mmaaa", "Jan 01 2014 12:20",
				TimeParser.parseTime("jan 1st 12.20pm"));

		// Sub Partition 3b: Cases that test for the wrapping of the Dates
		// The following cases are special because they are invalid, but the
		// code handles
		// them by wrapping the date to the appropriate valid date

		assertEquals("Negative month", "Nov 06 2013 00:00",
				TimeParser.parseTime("6/-1/2014"));

		assertEquals("month = 0", "Dec 06 2013 00:00",
				TimeParser.parseTime("6/0/2014"));

		assertEquals("Month beyond 12", "Jan 06 2015 00:00",
				TimeParser.parseTime("6/13/2014"));

		assertEquals("Time beyond 12", "Jan 06 2015 13:00",
				TimeParser.parseTime("6/13/2014 13am"));

		assertEquals("Time beyond 12", "Jan 07 2015 01:00",
				TimeParser.parseTime("6/13/2014 13pm"));

		// Invalid Cases

		assertEquals("Invalid order", "Error: Invalid Format\n",
				TimeParser.parseTime("4th 4pm jan"));

		assertEquals("Month not specified", "Error: Invalid Format\n",
				TimeParser.parseTime("4th 4pm"));

		assertEquals("Mixed formatting", "Error: Invalid Format\n",
				TimeParser.parseTime("jan"));

		assertEquals("Day and month not specified ", "Error: Invalid Format\n",
				TimeParser.parseTime("2014 4pm"));

		assertEquals("Contains invalid characters", "Error: Invalid Format\n",
				TimeParser.parseTime("4p.m"));

	}

}
